const { DataTypes } = require("sequelize");
const sequelize = require("../config/sequelize");
const TopicCategory = require("./topicCategory");

const Topic = sequelize.define(
  "Topic",
  {
    title: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "话题标题",
    },
    img: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "话题海报",
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "话题内容",
    },
    publishDate: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "话题发布时间",
    },
    readNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "阅读人数", //根据这个推荐资讯
    },
  },
  {
    sequelize: sequelize,
    tableName: "topic",
    underscored: true, //显示在数据库字段为下划线
    paranoid: true, //软删除
  }
);
Topic.belongsTo(TopicCategory, {
  constraints: false,
  foreignKey: "topicCategoryId",
  as: "topicCategory",
});

module.exports = Topic;
